<template>
  <div id="">
    <h1>TOP切换-2</h1>
    <!-- 顶部导航 -->
     <div id="btn-wrap">
        <div class="btn" v-for="(item, index) in nane" :key="index" @click="_index = index" :class="['btn',_index === index? 'active' : '']">
        </div>
     </div>
    <!-- 切换内容部分 -->
     <div id="con-wrap">
        <!-- 第一个盒子内容 -->
        <div class="con" v-if="_index === 0">
            <div class="list-cird" v-for="(item, index) in list1" :key="index">
                <img :src="item.img" alt="">
                <span class="list-crid-title"> {{ item.title }} </span>
                <span class="list-crid-content"> {{ item.intr }} </span>
            </div>
        </div>
    
        <!-- 第二个盒子内容 -->
         <div class="con" v-if="_index === 1">
            <div class="list-cird" v-for="(item, index) in list2" :key="index">
                <img :src="item.img" alt="">
                <span class="list-crid-title"> {{ item.title }} </span>
                <span class="list-crid-content"> {{ item.intr }} </span>
            </div>
      </div>
      <!-- 第三个盒子内容 -->
      <div class="con" v-if="_index === 2">
          <div class="list-cird" v-for="(item, index) in list3" :key="index">
              <img :src="item.img" alt="">
              <span class="list-crid-title"> {{ item.title }} </span>
              <span class="list-crid-content"> {{ item.intr }} </span>
          </div>
      </div>




    </div>
  </div>
</template>

<script lang="ts">
export default {
  name: 'TOP切换-2',
  props: {
  
  },
  data() {//数据
    return {//返回值
        nane: ['首页', '新闻', '产品']
    };
  },
  methods: {//方法
  
  }
}
</script>
<script lang="ts" setup>
// 引入类型定义
import { ref } from 'vue';//导入ref
import axios from 'axios';//导入axios

interface ListItem
{
    img: string;
    title: string;
    intr: string;
}

const _index = ref(0);

//请求列表li数据
const list1 = ref<ListItem[]>([]);
const data1=async ()=>{
    const response = await axios.get("https://mock.mengxuegu.com/mock/645b57ae7ba95d67784d6738/img/tabone");
    return response.data;
}
//回调函数
data1().then(
    (data)=>{
        list1.value=data;
    })
//请求列表li数据
const list2 = ref<ListItem[]>([]);
const data2=async ()=>{
    const response = await axios.get("https://mock.mengxuegu.com/mock/645b57ae7ba95d67784d6738/img/tabtwo");
    return response.data;
}
//回调函数
data2().then(
    (data)=>{
        list2.value=data;
    })
//请求列表li数据
const list3 = ref<ListItem[]>([]);
const data3=async ()=>{
    const response = await axios.get("https://mock.mengxuegu.com/mock/645b57ae7ba95d67784d6738/img/tabthree");
    return response.data;
}
//回调函数
data3().then(
    (data)=>{
        list3.value=data;
    })





</script>




<!-- 样式 -->
<style lang="scss">
  @use "@/assets/common.scss";

/* 资讯部分导航 */
#btn-wrap {
  margin-top: 2vh;
  width: 90%;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-bottom: 5px;
}

.btn {
  width: calc(100% / 3 - 2vh);
  margin: 0 1vh;
  height: 80px;
  font-size: 20px;
  text-align: center;
  font-weight: bold;
  line-height: 80px;
  border-radius: 0.75rem;
  color: #fff;
  background-color: #4cceff;
}

.active {
  color: #4cceff;
  background-color: rgba(255, 255, 255, 0.7);
}

/* 切换内容部分 */
#con-wrap {
  width: 90%;
  height: 100%;
  margin: 0 auto;
  border-radius: 10px;
  background-color: rgba(241, 242, 243, 0.9);
}

.con {
  width: 100%;
  height: auto;
  min-height: 60vh;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: start;
  flex-wrap: wrap;
}

.con::-webkit-scrollbar {
  width: 1px;
}

.list-cird {
  width: calc((100% / 2) - 30px);
  height: 100%;
  margin: 10px auto;
  background-color: rgba(76, 206, 255, 0.9);
  box-shadow: 5px 5px 5px rgba(85, 0, 255, 0.5);
  border-radius: 4px;
  box-shadow: 1px 1px 5px #eee;
}

.list-crid>img {
  width: calc(100% - 20px);
  height: 300px;
  display: block;
  margin: 10px auto;
}

.list-crid-title {
  font-size: 18px;
  width: calc(100% - 20px);
  display: block;
  line-height: 18px;
  padding: 10px 0;
  margin: 0 auto;
  font-weight: bold;
}

.list-crid-content {
  width: calc(100% - 20px);
  margin: 10px auto;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
}
</style>